/**
 * @Date: Mar 3, 2010 2:30:33 PM
 */
package com.philip.journal.core.bean;

import java.io.Serializable;
import java.lang.reflect.Method;

import org.apache.log4j.Logger;

import com.philip.journal.common.BeanUtils;
import com.philip.journal.core.Messages.Error;

/**
 * @author cry30
 */
public abstract class AbstractBean implements Serializable {

    /** Class logger. */
    private static Logger logger = Logger.getLogger(AbstractBean.class); // NOPMD by r39

    @Override
    public String toString() {
        final StringBuilder strBuilder = new StringBuilder();
        strBuilder.append("\n" + getClass() + "\n-------------------\n");

        String methodName;
        final Object[] emptyObj = {};
        for (final Method method : getClass().getMethods()) {
            methodName = method.getName();
            if (methodName.startsWith("get") && !"getClass".equals(methodName)) {

                strBuilder.append(BeanUtils.getPropertyName(methodName));
                strBuilder.append("=[");
                try {
                    strBuilder.append(method.invoke(this, emptyObj));
                } catch (final Exception ignore) {
                    logger.fatal(Error.IMPOSSIBLE);
                }
                strBuilder.append("]\n");
            }
        }
        strBuilder.append("\n");
        return strBuilder.toString();
    }
}
